<?php

/**
 * user actions.
 *
 * @package    lomejorde
 * @subpackage user
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */

require_once(sfConfig::get('sf_lib_dir').'/vendor/EpiFramework/EpiCurl.php');
require_once(sfConfig::get('sf_lib_dir').'/vendor/EpiFramework/EpiOAuth.php');
require_once(sfConfig::get('sf_lib_dir').'/vendor/EpiFramework/EpiTwitter.php');

class userActions extends sfActions
{
    public function executeShowNominations(sfWebRequest $request){
        $this->user = $this->getRoute()->getObject();
        
        $this->nominations = $this->user->getNominations();
        
        if(!$this->getUser()->isAuthenticated()){
            $this->twitter = new EpiTwitter(sfConfig::get('app_twitter_consumer_key'), sfConfig::get('app_twitter_consumer_secret'));
        
            $fbconfig['appid' ]     = sfConfig::get('app_facebook_appid');
            $fbconfig['secret']     = sfConfig::get('app_facebook_secret');
            $fbconfig['baseurl']    = sfContext::getInstance()->getRouting()->generate('apply_facebook', array(), true);

            try {
                include_once sfConfig::get('sf_lib_dir').'/vendor/PHP-SDK-3.0-Graph-API-Facebook/facebook.php';
            } catch(Exception $o) {
                error_log($o);
            }
            // Create our Application instance.
            $facebook = new Facebook(array(
                'appId'  => $fbconfig['appid'],
                'secret' => $fbconfig['secret'],
                'cookie' => true,
            ));

            $this->fb_login_url = $facebook->getLoginUrl(
                array(
                    'scope' => 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown',
                    'redirect_uri' => $fbconfig['baseurl']
                ));
        }
    }
    
    public function executeShowVotes(sfWebRequest $request){
        $this->user = $this->getRoute()->getObject();
        
        $this->votes = $this->user->getVotes();
        
        if(!$this->getUser()->isAuthenticated()){
            $this->twitter = new EpiTwitter(sfConfig::get('app_twitter_consumer_key'), sfConfig::get('app_twitter_consumer_secret'));
        
            $fbconfig['appid' ]     = sfConfig::get('app_facebook_appid');
            $fbconfig['secret']     = sfConfig::get('app_facebook_secret');
            $fbconfig['baseurl']    = sfContext::getInstance()->getRouting()->generate('apply_facebook', array(), true);

            try {
                include_once sfConfig::get('sf_lib_dir').'/vendor/PHP-SDK-3.0-Graph-API-Facebook/facebook.php';
            } catch(Exception $o) {
                error_log($o);
            }
            // Create our Application instance.
            $facebook = new Facebook(array(
                'appId'  => $fbconfig['appid'],
                'secret' => $fbconfig['secret'],
                'cookie' => true,
            ));

            $this->fb_login_url = $facebook->getLoginUrl(
                array(
                    'scope' => 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown',
                    'redirect_uri' => $fbconfig['baseurl']
                ));
        }
    }
}
